package com.tich.program.controller;

import com.tich.api.domain.dto.ProgramTicketAddDTO;
import com.tich.api.domain.dto.ProgramTicketDeductDTO;
import com.tich.api.domain.vo.ProgramClientSelectVO;
import com.tich.constant.ResponseMessageConstant;
import com.tich.program.service.ClientService;
import com.tich.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/client")
public class ClientController {

    @Autowired
    private ClientService clientService;

    /**
     * 根据id查询节目以及门票信息
     * @param programId
     * @param ticketId
     * @return
     * */
    @GetMapping("/program")
    public Result<ProgramClientSelectVO> programClientSelect(Long programId, Long ticketId){
        log.info("查询节目以及门票的信息, programId:{}, ticketId:{}", programId, ticketId);
        return Result.success(ResponseMessageConstant.QUERY_SUCCESS,
                clientService.programClientSelect(programId, ticketId));
    }

    /**
     * 扣减门票数量
     * @param programTicketDeductDTO
     * @return
     * */
    @PutMapping("/program/ticket/deduct")
    public Result<Boolean> programTicketDeduct(@RequestBody ProgramTicketDeductDTO programTicketDeductDTO){
        log.info("扣减门票库存：{}", programTicketDeductDTO);
        return Result.success(ResponseMessageConstant.DEDUCT_SUCCESS,
                clientService.programTicketDeduct(programTicketDeductDTO));
    }

    /**
     * 取消订单，恢复门票库存
     * @param programTicketAddDTO
     * @return
     * */
    @PutMapping("/program/ticket/add")
    public Result<Boolean> programTicketAdd(@RequestBody ProgramTicketAddDTO programTicketAddDTO){
        log.info("取消订单，恢复门票库存：{}", programTicketAddDTO);
        return Result.success(ResponseMessageConstant.CANCEL_SUCCESS,
                clientService.programTicketAdd(programTicketAddDTO));
    }

    /**
     * 查询门票种类
     * @param ticketId
     * @return
     */
    @GetMapping("/program/ticket/category")
    public Result<String> ticketCategorySelect(@RequestParam Long ticketId){
        return Result.success(ResponseMessageConstant.QUERY_SUCCESS,
                clientService.ticketCategorySelect(ticketId));
    }

}
